Skip to content

Fix dangling assignment of relationpath for Postgres 18.#13

Open
robert-pang wants to merge 1 commit into
klando:masterfrom
robert-pang:fix-relationpath-assignment
Open

Fix dangling assignment of relationpath for Postgres 18.#13
robert-pang wants to merge 1 commit into
klando:masterfrom
robert-pang:fix-relationpath-assignment

Conversation

@robert-pang

@robert-pang robert-pang commented May 6, 2026

Copy link
Copy Markdown
Contributor

When compiling pgfincore with Postgres 18, we observed the following compiler warning:

pgfincore/pgfincore.c:366:24: error: object backing the pointer 'fctx->relationpath' will be destroyed at the end of the full-expression [-Werror,-Wdangling-assignment]
  366 |                 fctx->relationpath = relpathpg(fctx->rel, forkName);
      |                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pgfincore/pgfincore.c:154:9: note: expanded from macro 'relpathpg'
  154 |         relpathbackend((rel)->rd_locator, (rel)->rd_backend, (forkname_to_number(text_to_cstring(forkName)))).str
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
postgres/src/include/common/relpath.h:143:2: note: expanded from macro 'relpathbackend'
  143 |         GetRelationPath((rlocator).dbOid, (rlocator).spcOid, (rlocator).relNumber, \
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  144 |                                         backend, forknum)
      |                                         ~~~~~~~~~~~~~~~~~
pgfincore/pgfincore.c:640:17: error: object backing the pointer 'relationpath' will be destroyed at the end of the full-expression [-Werror,-Wdangling-assignment]
  640 |         relationpath = relpathpg(rel, forkName);
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~
pgfincore/pgfincore.c:154:9: note: expanded from macro 'relpathpg'
  154 |         relpathbackend((rel)->rd_locator, (rel)->rd_backend, (forkname_to_number(text_to_cstring(forkName)))).str
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
postgres/src/include/common/relpath.h:143:2: note: expanded from macro 'relpathbackend'
  143 |         GetRelationPath((rlocator).dbOid, (rlocator).spcOid, (rlocator).relNumber, \
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  144 |                                         backend, forknum)
      |                                         ~~~~~~~~~~~~~~~~~
pgfincore/pgfincore.c:949:24: error: object backing the pointer 'fctx->relationpath' will be destroyed at the end of the full-expression [-Werror,-Wdangling-assignment]
  949 |                 fctx->relationpath = relpathpg(fctx->rel, forkName);
      |                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pgfincore/pgfincore.c:154:9: note: expanded from macro 'relpathpg'
  154 |         relpathbackend((rel)->rd_locator, (rel)->rd_backend, (forkname_to_number(text_to_cstring(forkName)))).str
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
postgres/src/include/common/relpath.h:143:2: note: expanded from macro 'relpathbackend'
  143 |         GetRelationPath((rlocator).dbOid, (rlocator).spcOid, (rlocator).relNumber, \
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  144 |                                         backend, forknum)
      |                                         ~~~~~~~~~~~~~~~~~

From what we notice, GetRelationPath() in Postgres 18 returns the relation path as the following struct as an rvalue that lasts for the duration of the assignment only:

typedef struct RelPathStr
{
	char		str[REL_PATH_STR_MAXLEN + 1];
} RelPathStr;

To keep a reference to the str safely, we propose a fix to duplicate it using pstrdup() to resolve the compiler warning.

…alue of

GetRelationPath() is an rvalue for the duration of the assignment only.

Signed-off-by: Robert Pang <robertpang@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant